<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dubbo 与 ZooKeeper 架构详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 1rem;
            font-family: 'Courier New', monospace;
            overflow-x: auto;
        }
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl font-bold mb-6">Dubbo 与 ZooKeeper</h1>
                <p class="text-xl opacity-90 mb-8">深入理解分布式服务架构中的注册中心机制</p>
                <div class="flex justify-center space-x-4">
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                        <i class="fas fa-server mr-2"></i>服务注册
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                        <i class="fas fa-search mr-2"></i>服务发现
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-blur-sm rounded-lg px-6 py-3">
                        <i class="fas fa-cog mr-2"></i>动态配置
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="max-w-4xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">在</span>Dubbo 中，ZooKeeper 扮演着注册中心的角色，用于存储和管理服务提供者（Producer）和消费者（Consumer）的信息。它不仅是一个简单的存储系统，更是整个分布式服务架构的核心枢纽，确保服务的动态发现、负载均衡和高可用性。
                </p>
            </div>
        </div>

        <!-- Architecture Diagram -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="text-3xl font-bold text-center mb-8 text-gray-800">系统架构概览</h2>
            <div class="mermaid">
                graph TB
                    subgraph "服务提供者"
                        P1[Provider 1]
                        P2[Provider 2]
                        P3[Provider 3]
                    end
                    
                    subgraph "ZooKeeper 集群"
                        Z[ZooKeeper<br/>注册中心]
                        subgraph "数据结构"
                            PR[/dubbo/service/providers]
                            CO[/dubbo/service/consumers]
                            CF[/dubbo/service/configurators]
                            RT[/dubbo/service/routers]
                        end
                    end
                    
                    subgraph "服务消费者"
                        C1[Consumer 1]
                        C2[Consumer 2]
                    end
                    
                    P1 -->|注册| PR
                    P2 -->|注册| PR
                    P3 -->|注册| PR
                    
                    C1 -->|订阅| PR
                    C2 -->|订阅| PR
                    C1 -->|注册| CO
                    C2 -->|注册| CO
                    
                    Z -->|通知| C1
                    Z -->|通知| C2
                    
                    style Z fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style PR fill:#f0f4f8,stroke:#667eea,stroke-width:2px
                    style CO fill:#f0f4f8,stroke:#667eea,stroke-width:2px
                    style CF fill:#f0f4f8,stroke:#667eea,stroke-width:2px
                    style RT fill:#f0f4f8,stroke:#667eea,stroke-width:2px
            </div>
        </div>

        <!-- Service Provider Section -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-server text-purple-600 mr-3"></i>服务提供者信息的存储
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-cloud-upload-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">注册服务</h3>
                    <p class="text-gray-600 leading-relaxed">
                        当一个服务提供者启动时，它会将自己提供的服务注册到 ZooKeeper 中。这包括服务的接口名、版本号、IP 地址、端口号等元数据信息。ZooKeeper 会为每个服务接口创建一个 znode，并在其下创建子节点来存储每个提供者的信息。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-sitemap"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">znode 结构</h3>
                    <div class="space-y-3">
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/providers/</code>
                        </div>
                        <p class="text-sm text-gray-600">服务提供者的目录</p>
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/providers/provider_url</code>
                        </div>
                        <p class="text-sm text-gray-600">每个服务提供者对应一个子节点，节点名是服务的 URL</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Service Consumer Section -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-users text-purple-600 mr-3"></i>服务消费者信息的存储
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-bell"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">订阅服务</h3>
                    <p class="text-gray-600 leading-relaxed">
                        服务消费者启动时，会向 ZooKeeper 订阅所需的服务。这意味着消费者会在 ZooKeeper 中注册自己的信息，以便动态感知服务提供者的变化，如新提供者加入或某个提供者下线等。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-folder-tree"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">znode 结构</h3>
                    <div class="space-y-3">
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/consumers/</code>
                        </div>
                        <p class="text-sm text-gray-600">服务消费者的目录</p>
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/consumers/consumer_url</code>
                        </div>
                        <p class="text-sm text-gray-600">每个服务消费者对应一个子节点</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Configuration Section -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-cogs text-purple-600 mr-3"></i>配置和路由信息的存储
            </h2>
            
            <div class="bg-white rounded-xl shadow-lg p-8">
                <p class="text-gray-700 mb-6 leading-relaxed">
                    除了服务提供者和消费者的信息外，Dubbo 还会在 ZooKeeper 中存储一些动态配置和路由信息，如负载均衡策略、权重配置、路由规则等。
                </p>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gray-50 rounded-lg p-6">
                        <h4 class="font-bold text-gray-800 mb-3">
                            <i class="fas fa-sliders-h text-purple-600 mr-2"></i>配置节点
                        </h4>
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/configurators/</code>
                        </div>
                        <p class="text-sm text-gray-600 mt-2">用于存储服务的动态配置</p>
                    </div>
                    
                    <div class="bg-gray-50 rounded-lg p-6">
                        <h4 class="font-bold text-gray-800 mb-3">
                            <i class="fas fa-route text-purple-600 mr-2"></i>路由节点
                        </h4>
                        <div class="code-block">
                            <code>/dubbo/com.example.Service/routers/</code>
                        </div>
                        <p class="text-sm text-gray-600 mt-2">用于存储服务的路由规则</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Node Types -->
        <div class="max-w-6xl mx-auto mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-database text-purple-600 mr-3"></i>节点类型
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-xl p-8 border border-purple-200">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-purple-600 rounded-full flex items-center justify-center text-white mr-4">
                            <i class="fas fa-clock"></i>
                        </div>